package com.zzy.backend.consumer.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author molimark<br />
 * @date: 2023/3/18 16:28<br/>
 * @description: <br/>
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Player {
    private Integer id;
    private Integer sx;
    private Integer sy;
    private List<Integer> steps; //玩家每一步的方向

    private boolean check_tail_increasing(int step){ // 检验当前回合，蛇的长度是否增加
        if(step <= 10)return true;
        if(step % 3 == 1)return true;
        return false;
    }

    public List<Cell> getCells(){
        List<Cell> res = new LinkedList<>();

        int[] dx = {-1,0,1,0};
        int[] dy = {0,1,0,-1};

        int x = sx, y = sy;
        int step=0;

        res.add(new Cell(x,y));
        for(int d : steps){
            x+=dx[d];
            y+=dy[d];
            if(!check_tail_increasing(++step)){
                res.remove(0);
            }
            res.add(new Cell(x,y));
        }

        return res;
    }

    public String getStepsString(){
        StringBuilder res = new StringBuilder();
        for(int d:steps){
            res.append(d);
        }
        return res.toString();
    }
}
